<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;
if ((isset($_POST["submit"]))) {
    $updateSQL = sprintf("UPDATE pethospital SET vet_hospital=%s, vet_city=%s, vet_district=%s, vet_address=%s, vet_phone=%s, vet_maincontact=%s, vet_mobilephone=%s, vet_sspca_partner=%s, preferential=%s WHERE hospital_Id=%s",
                       GetSQLValueString($_POST['vet_hospital'], "text"),
                       GetSQLValueString($_POST['vet_city'], "text"),
                       GetSQLValueString($_POST['vet_district'], "text"),
                       GetSQLValueString($_POST['vet_address'], "text"),
                       GetSQLValueString($_POST['vet_phone'], "text"),
                       GetSQLValueString($_POST['vet_maincontact'], "text"),
                       GetSQLValueString($_POST['vet_mobilephone'], "text"),
                       GetSQLValueString($_POST['vet_sspca_partner'], "text"),
                       GetSQLValueString($_POST['vet_spay_allocation'], "text"),
                       GetSQLValueString($_POST['hospital_Id'], "int"));

    $db->query($updateSQL);
    header("location:".$_SERVER['PHP_SELF']."?result=suc&hospital_Id=".$_POST['hospital_Id']);
}

$id = "-1";
if (isset($_GET['hospital_Id'])) {
    $id = $_GET['hospital_Id'];
}

$sql = sprintf("SELECT * FROM pethospital where hospital_Id=%s", GetSQLValueString($id, "int"));
$res = $db->query($sql);
$row = $db->fetch($res);

include('AdminPanel.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Pet Hospital</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
  	<?php
    if($_GET['result'] && 'suc' == $_GET['result']) {
    ?>
    <tr valign="baseline">
      <td colspan="2" nowrap="nowrap" align="center"><font color="green">更新成功...</font></td>
    </tr>
    <?php
    }
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Hospital_Id:</td>
      <td><?php echo $row['hospital_Id']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">宠物诊所/医院:</td>
      <td><input type="text" name="vet_hospital" value="<?php echo htmlentities($row['vet_hospital'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">城市:</td>
      <td><label>
        <select name="vet_city">
        <option value="上海市">上海市</option>
        </select>
      </label></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">区县:</td>
      <td>
      <select name="vet_district">
        <option value="">-请选择-</option>
        <?php
        foreach($district_arr as $_key => $_value) {
        	if($_value == $row['vet_district']) {
        		echo '<option value="'.$_value.'" selected>'.$_value.'</option>';
        	}
        	else {
        		echo '<option value="'.$_value.'">'.$_value.'</option>';
        	}        	
        }        
        ?>
      </select>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">地址:</td>
      <td><input type="text" name="vet_address" value="<?php echo htmlentities($row['vet_address'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">电话:</td>
      <td><input type="text" name="vet_phone" value="<?php echo htmlentities($row['vet_phone'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">诊所联系人名字:</td>
      <td><input type="text" name="vet_maincontact" value="<?php echo htmlentities($row['vet_maincontact'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">手机:</td>
      <td><input type="text" name="vet_mobilephone" value="<?php echo htmlentities($row['vet_mobilephone'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">分会合作伙伴:</td>
      <td>
      <?php
      if('Y' == $row['vet_sspca_partner']) {
      	  $radio1 = 'checked';
      	  $radio2 = '';
      }
      else {
      	  $radio1 = '';
      	  $radio2 = 'checked';
      }
      ?>
      	<input type="radio" name="vet_sspca_partner" value="Y" <?php echo $radio1?>/> 是  
      	<input type="radio" name="vet_sspca_partner" value="N" <?php echo $radio2?>/> 否 
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">合作优惠:</td>
      <td><textarea name="vet_spay_allocation" cols="50" rows="10"><?php echo htmlentities($row['preferential'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td>
      	<input type="submit" id="submit" name="submit" value="Update record" />&nbsp;&nbsp;
        <input type="button" id="button" onclick="window.location.href='ShowPetHospital.php'" value="Back">
      </td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="center" nowrap="nowrap">&nbsp;</td>
    </tr>
  </table>
  <input type="hidden" name="hospital_Id" value="<?php echo $row['hospital_Id']; ?>" />
</form>
<p>&nbsp;</p>
</body>
</html>